package dsk.demo.product.service.impl;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dsk.demo.product.dao.CustomerLinkManDao;
import dsk.demo.product.entity.CustomerEntity;
import dsk.demo.product.entity.CustomerLinkManEntity;
import dsk.demo.product.service.CustomerLinkManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerLinkManServiceImpl extends ServiceImpl<CustomerLinkManDao, CustomerLinkManEntity> implements CustomerLinkManService {

    @Autowired
    private CustomerLinkManDao customerLinkManDao;

    @Override
    public List<CustomerLinkManEntity> excel2CustomerLinkManEntityList(MultipartFile file) throws Exception {
        try {
            InputStream inputStream = file.getInputStream();
            ExcelReader reader = ExcelUtil.getReader(inputStream);
            Map<String, String> map = new HashMap<>();
            map.put("国家","area");
            map.put("姓名","name");
            map.put("邮箱","email");
            map.put("电话","phone");
            map.put("公司ID","companyId");

            reader.setHeaderAlias(map);
            List<CustomerLinkManEntity> all = reader.readAll(CustomerLinkManEntity.class);
            return all;
        }catch (Exception e) {
            System.out.println("Excel 解析失败");
            throw new Exception("Excel 解析失败");
        }
    }

    @Override
    public void insertBatch(List<CustomerLinkManEntity> list) {
        customerLinkManDao.insertBatch(list);
    }

    @Override
    public List<CustomerLinkManEntity> getAutoSendLinkMan(String index, String hsCode) {
        return this.getBaseMapper().getAutoSendLinkMan(index,hsCode);
    }
}
